from PySide2.QtCore import QUrl, QEvent
from PySide2.QtWidgets import QApplication
from PySide2.QtMultimedia import QMediaContent, QMediaPlayer
from PySide2.QtMultimediaWidgets import QVideoWidget


class HVideoWidget(QVideoWidget):
    
    def __init__(self):
        super(HVideoWidget, self).__init__()
        
        self.setupUi()
        
    
    def setupUi(self):
        self.player = QMediaPlayer()
        self.player.setVideoOutput(self)
        desktop = QApplication.desktop()
        self.resize(desktop.width()*0.5, desktop.height()*0.5)        
        
    def play(self, url):
        self.player.setMedia(QMediaContent(QUrl(url)))
        self.player.play()
        
    def closeEvent(self, event): 
        if event.type() == QEvent.Close:
            self.player.stop()
